package components;

import com.uqbar.vainilla.DeltaState;
import components.direction.Direction;

public class Walking extends WalkerState {

	public Walking(Walker walker){
		super(walker);
	}
	
	public void update(DeltaState delta){
		if(this.getWalker().canMove()){
				this.getWalker().generciMove(delta, this.getWalker().getSpeed(), this.getDir().getVx() , this.getDir().getVy());	
				this.checkArrive();
		}
		else {
			this.getWalker().setWalkerState(new ChangingDirection(this.getWalker()));
		}
	}
	
	private void checkArrive() {
		if (this.getWalker().getMovingTo().arrived2(this.getWalker(), this.getDir())){
			this.centerComponent();
			this.getWalker().setWalkerState(new ChangingDirection(this.getWalker()));
		}
	}
	private void centerComponent() {
		this.getWalker().getScene().
		getMapMatrix().centerComponentOnSlot(this.getWalker(), this.getWalker().getMovingTo().getX(), this.getWalker().getMovingTo().getY());
	}
	public Direction getDir(){
		return this.getWalker().getDir();
	}
}
